#!/usr/bin/env python
# -*- coding: utf-8 -*-

from suffix_tree import GeneralisedSuffixTree
import sys
#import gc

#s1 = unicode(sys.argv[1], 'utf-8')
#s2 = unicode(sys.argv[2], 'utf-8')

#s1 = u'mississippi'
#s2 = u'sippissi'

#s1 = u'一寸光阴一寸金';
#s2 = u'寸金难买寸光阴';

longest = None

def return_sub(liste):
    #for x in liste:
        #x = unicode(x, 'utf-8')
    
    stree = GeneralisedSuffixTree(liste) 
    longest = None
    maxlength = 1
    
    for shared in stree.sharedSubstrings(2):
        #print '-'*70
        for (seq,start,stop) in shared:
            #print seq,
            #print '['+str(start)+':'+str(stop)+']',
            length = stop - start
            if (length) > maxlength:
                maxlength = length
                longest = stree.sequences[seq][start:stop]
    #print(maxlength)
    if longest:
        #gc.collect()
        return longest.encode('utf-8')
    else:
        return ""
    
            #print ss.encode('utf-8'),
            
            #print at.encode('utf-8')
    #print '='*70 
